package net.xumf.support.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import net.xumf.support.exception.NotFoundEnumInfoException;

import java.util.Arrays;

/**
 * 连接池类型
 */
public enum ColumnTypeEnum {

    NULL(0), // 无
    LAYOUT(1), // 布局
    DIMENSION(2), // 维度
    STATISTICS(3), // 统计
    CALCULATION(4),; // 计算

    @JsonValue
    public int getCode() {
        return code;
    }

    private int code;

    ColumnTypeEnum(int code) {
        this.code = code;
    }

    @JsonCreator
    public static ColumnTypeEnum getByCode(int code) {

        return Arrays.stream(values()).filter(o -> o.code == code).findAny()
                .orElseThrow(() -> new NotFoundEnumInfoException(CodeEnum.ENUM_NOT_FOUND_ERROR));
    }

}
